/*
 * extraMath.h
 *
 *  Created on: 24-nov.-2013
 *      Author: Axel
 */

#ifndef EXTRAMATH_H_
#define EXTRAMATH_H_

namespace math {

	#define PI 3.14159265358979323846
	#define E  2.718281828459
	#define ToRadian(x) (float)(((x) * PI / 180.0f))
	#define ToDegree(x) (float)(((x) * 180.0f / PI))

	template <class T>
	T abs_axel(T x) {
		return (x<0)? -x : x;
	}

	template <class T>
	T posDif_axel(T x, T y) {
		return (x < y)? y-x: x-y;
	}

	template <class T>
	T max_axel(T x, T y) {
		return (x < y)? y: x;
	}

	template <class T>
	T min_axel(T x, T y) {
		return (x < y)? x: y;
	}

	template <class T>
	T copysign_axel(T x, T y) {
		if (x > 0)
			return (y < 0)? -x: x;
		else
			return (y < 0)? x: -x;
	}

	template <class T>
	T root_axel(T number, int degree) {
		T result;
		for(int x=0;x*x<=number;x++) {
			result = 1;
			for(int macht=0;macht<degree;macht++)
				result *= x;
			if (result == number)
				return x;
		}
		return -1;
	}

	template <class T>
	T hypot_axel(T number, T next) {
		return root_axel(power_axel(number,2) + power_axel(next,2),2);
	}

	template <class T>
	T round_axel(T x) {
		if (x > 0)
			return ((x - (int) x) > 0.5)? ((int) x +1): ((int) x);
		else
			return ((x + (int) x) > 0.5)? ((int) x +1): ((int) x);
	}

	template <class T>
	T roundup_axel(T x) {
		return (int) x + 1;
	}

	template <class T>
	T rounddown_axel(T x) {
		return (int) x -1;
	}

	double exp_axel(int x);

	double exp2_axel(int x);

	double power_axel(double base, double power);

	double faculty_axel(double x);

	double cosh_axel(double x);

	double sinh_axel(double x);

	double tanh_axel(double x);

	double cos_axel(double x);

	double sin_axel(double x);

	double tan_axel(double x);

	double controlAngle(double x);

}


#endif /* EXTRAMATH_H_ */
